package com.xiaoxiao.ssos.base.utils;

import com.xiaoxiao.ssos.entity.User;
import com.xiaoxiao.ssos.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import org.apache.shiro.SecurityUtils;

import java.util.Map;

public class UserUtils {
    public static Long getUserId(){
        Claims claims = JwtUtils.parseToken((String) SecurityUtils
                .getSubject().getPrincipals()
                .getPrimaryPrincipal());
        Map map = (Map) claims.get("username");
        return ((Integer)map.get("id")).longValue();
    }
    public static String getUserName(){
        Claims claims = JwtUtils.parseToken((String) SecurityUtils
                .getSubject().getPrincipals()
                .getPrimaryPrincipal());
        Map map = (Map) claims.get("username");
        return  map.get("username").toString();
    }
}
